<template>
  <div class="app-container">
    <!-- <h1>充值拨比</h1> -->

    <div class="boxlaw">
      <div class="comform">
        <ComForm
          ref="comForm"
          @EventReset="resetFn"
          @EventOnsubmit="queryFn"
          :list="comForm"
        >
        </ComForm>
      </div>
      <el-button
        @click="addShowFn"
        v-hasPermi="['financial:payCommision:add']"
        type="primary"
        >新增</el-button
      >
      <ComTable
        @handleCurrentChange="CurrentPageChangeFn"
        @handleSizeChange="currentPageSizeChangeFn"
        :key="random"
        :list="tableList"
        :modes="tableModes"
        :config="{ border: true, loading }"
        :pagination="{ total: paging.total, pageNum: paging.pageNum }"
      >
        <el-table-column #default="{ row }" align="left">
          <template>
            <!-- "
              $router.push({
                path: '/contentPlatform/laws/laws-details',
                query: row,
              })
            " -->
            <!-- v-hasPermi="['base:docModule:list']" -->
            <el-button
              @click="editShowFn(row)"
              v-hasPermi="['financial:payCommision:getInfo']"
              plain
              size="mini"
              type="primary"
              >修改</el-button
            >
          </template>
          <template>
            <el-button
              plain
              size="mini"
              v-hasPermi="['financial:payCommision:remove']"
              type="primary"
              @click="deleteFn(row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </ComTable>
    </div>
    <RechargeDlg
      ref="addAntEdit"
      @EventGetData="getData"
      :dialogVisible.sync="dialogVisible"
    ></RechargeDlg>
  </div>
</template>

<script>
import ComForm from "../../../components/comForm.vue";

import ComTable from "../../../components/comTable.vue";

// import { getdocGetTypeApi } from "@/wss/api/ContentSupervision.js";

import {
  getPayCommisionListApi,
  getPayCommisionStatusApi,
  getPayCommisionAddApi,
  getPayCommisionEditApi,
} from "@/wss/api/financial/payCommision.js";
import RechargeDlg from "./RechargeDlg.vue";
export default {
  name: "laws",
  dicts: ["sys_normal_disable"],
  components: { ComForm, ComTable, RechargeDlg },

  data() {
    return {
      // 是否显示添加对话框
      dialogVisible: false,
      initSelectValue: "",
      //   存放职位的id
      postionIdStrArr: [],
      // 判断是否是图文,默认是1。
      isImgText: "1",
      // 加载
      loading: false,
      paging: { pageNum: 1, pageSize: 10, type: "1", total: 10 },
      // 切换筛选状态，不更新bug修复
      random: "",
      //   职位列表
      postionList: [],
      // 表格的数据
      tableList: [],
      tableModes: [
        {
          type: "selection",
        },
        {
          showOverflowTooltip: true,

          width: 200,
          label: "消费类型",
          mode: "type",
          showOverflowTooltip: true,
          options: [
            {
              l: "充值",
              v: 1,
            },
            {
              l: "VIP",
              v: 2,
            },
          ],
        },

        {
          label: "角色",
          mode: "postionName",
          showOverflowTooltip: true,
        },
        {
          label: "拨比方式",
          mode: "commisionType",
          effectiveStatus: true,
          width: 100,
          align: "center",
          isShowTag: true,
          options: [
            {
              l: "比例",
              v: 1,
            },
            {
              l: "次数",
              v: 2,
            },
            {
              l: "时长",
              v: 3,
            },
          ],
        },
        {
          label: "拨比（元）",
          mode: "commision",
        },
      ],
      comForm: {
        modes: [
          {
            formType: "select",
            mode: "postionId",
            label: "角色",
            value: "",
            select: [],
          },
        ],
      },
    };
  },

  mounted() {
    this.getPayCommisionListFn(this.paging);
  },
  methods: {
    // 显示添加对话框
    addShowFn() {
      this.dialogVisible = true;
    },
    // 删除
    async deleteFn(row) {
      try {
        await this.$modal.confirm("确定删除吗");
        let { code, msg } = await getPayCommisionStatusApi({ id: row.idStr });
        if (code == 200) {
          this.$modal.msgSuccess(msg);
          this.getPayCommisionListFn();
        }
      } catch (error) {}
      // console.log(result);
    },
    // 重设函数
    resetFn() {},
    // 当前页发生改变时候
    CurrentPageChangeFn(pageNUm) {
      this.paging.pageNum = pageNUm;
      this.getPayCommisionListFn(this.paging);
    },
    // 页容量发生改变时候
    currentPageSizeChangeFn(pageSize) {
      this.paging.pageSize = pageSize;
      this.getPayCommisionListFn(this.paging);
    },
    // 筛选数据
    queryFn(arr) {
      arr.forEach((item) => {
        for (const key in item) {
          this.paging[key] = item[key];
        }
      });
      this.currentSelect = this.initSelectValue;
      console.log(this.paging, "查询");
      this.paging.pageNum = 1;
      this.getPayCommisionListFn(this.paging);
    },

    // 获取列表数据
    async getPayCommisionListFn() {
      this.loading = true;

      const { rows, code } = await getPayCommisionListApi(this.paging);
      console.log(rows, "列表");
      if (code == 200) {
        this.tableList = rows;
        this.tableList.forEach((item) => {
          // 判断是次数|时长|比例
          switch (item.commisionType) {
            case "1":
              item.commision = item.commision + "%";
              break;
            case "2":
              item.commision = item.commision + "/" + "次数";
              break;
            case "3":
              item.commision = item.commision + "/" + "时长";

              break;
            default:
              break;
          }
          // 动态生成筛选条件
          if (!this.postionIdStrArr.includes(item.postionIdStr)) {
            this.postionIdStrArr.push(item.postionIdStr);
            this.postionList.push({
              label: item.postionName,
              value: item.postionIdStr,
            });
          }
        });

        this.comForm.modes[0].select = this.postionList;
        console.log(this.postionList);
        this.loading = false;
      }
    },

    // 添加|修改
    async getData(data) {
      console.log(data);
      let myCode, myMsg;
      //   修改
      if (data.idStr) {
        data.id = data.idStr;
        let { msg, code } = await getPayCommisionEditApi(data);
        myCode = code;
        myMsg = msg;
        // 保存
      } else {
        let { msg, code } = await getPayCommisionAddApi(data);
        myCode = code;
        myMsg = msg;
      }
      if (myCode == 200) {
        this.$modal.msgSuccess(myMsg);
        this.getPayCommisionListFn();
        this.dialogVisible = false;
      }
    },
    //修改
    async editFn(data) {
      // 赋值当前类型（在线|图文）

      const { msg, code } = await getCommisionditApi(data);
      console.log(msg);
      if (code == 200) {
        this.$modal.msgSuccess(msg);

        this.getPayCommisionListFn();
      }
    },
    // 查看
    async editShowFn(row) {
      this.dialogVisible = true;
      this.$refs.addAntEdit.getDetailFn(row);
      // console.log(row);
    },
  },
};
</script>

<style lang ="scss" scoped>
.comform {
  margin-top: 20px;
}
</style>